# -*- coding: utf-8 -*-
"""
Created on Thu Jul 20 10:51:36 2023

@author: skunk69
"""

from mongoengine import Document, EmbeddedDocument
from mongoengine import StringField, IntField, EmbeddedDocumentField
from mongoengine import ListField, DictField

class Content(EmbeddedDocument):
    instruction = StringField()
    items = DictField(required=True)
    reverse_items = ListField(IntField())
    scales = ListField(StringField())
    scales_items = ListField(ListField(IntField()))
    factors = ListField(StringField())
    factors_scales = ListField(ListField(StringField()))
    rating = ListField(StringField(),required=True)
    score_rules = ListField(IntField(),required=True)
    
class General_Scales(Document):
    chinese_name = StringField(unique=True,required=True)
    english_name = StringField(unique=True,required=True)
    abbreviation = StringField(unique=True,required=True)
    category = StringField(required=True)
    outline = StringField()
    contents = EmbeddedDocumentField(Content,required=True)
    implementation = StringField()
    measurements = DictField()
    interpretation = StringField()
    applications = StringField()
    
if __name__ == "__main__":
    
    # example：general scale
    chinese_name = '中国大五人格问卷（简式版）'
    english_name = 'Chinese Big Five Personality Inventory, Brief Version'
    abbreviation = 'BFPI-B'
    category = u'人格评估量表'
    outline = u'概述'
    instruction = u'指导语'
    items = {1:u'请选择',2:u'请选择',3:u'请选择',4:u'请选择',5:u'请选择',
             6:u'请选择',7:u'请选择',8:u'请选择',9:u'请选择',10:u'请选择'}
    reverse_items = [2,7]
    scales = ['神经质','严谨性','宜人性','开放性','外向性']
    scales_items = [[1,3],[2,4],[5,6],[7,9],[8,10]]
    factors = ['大三','大二']
    factors_scales = [['神经质','严谨性','宜人性'],['开放性','外向性']]
    rating = ['是','否']
    score_rules = [0,1]
    implementation = u'实施方法'
    measurements = {'reliability':u'信度','validity':u'效度'}
    interpretation = u'结果分析方法'
    applications = u'应用情况'
    
    contents = Content(instruction=instruction)
    contents.items = items
    contents.reverse_items = reverse_items
    contents.scales = scales
    contents.scales_items = scales_items
    contents.factors = factors
    contents.factors_scales = factors_scales
    contents.rating = rating
    contents.score_rules = score_rules
    
    general_scales = General_Scales(contents=contents)
    general_scales.chinese_name = chinese_name
    general_scales.english_name = english_name
    general_scales.abbreviation = abbreviation
    general_scales.category = category
    general_scales.outline = outline
    general_scales.implementation = implementation
    general_scales.measurements = measurements
    general_scales.interpretation = interpretation
    general_scales.applications = applications
        
    print(general_scales.to_json(indent=2,ensure_ascii=False))
    